package com.jml.原子引用;


import java.util.Comparator;
import java.util.concurrent.atomic.AtomicReference;
import jdk.nashorn.internal.objects.annotations.Getter;

/**
 * @author:jml
 * @date: 2019/4/29 10:42
 * @description：
 */
class User  /*implements Comparator<User>*/ {
    int age;
    String userName;

    public User( String userName,int age) {
        this.age = age;
        this.userName = userName;
    }

    @Override
    public String toString() {
        return "User{" +
                "age=" + age +
                ", userName='" + userName + '\'' +
                '}';
    }


}
public class AtomicRefererDemo {
    public static void main(String[] args) {
        User z3=new User("z3",22);
        User z4=new User("z3",22);
        User li4=new User("li4",25);
        AtomicReference<User> atomicReference = new AtomicReference<User>();
        //把主内存的值设置为z3
        atomicReference.set(z3);
        //判断主内存的值和这里的z3是不是相等，相等就设置为li4
        boolean b = atomicReference.compareAndSet(z4, li4);
        System.out.println(b+":  "+atomicReference.toString());
    }
}
